package com.trainshop.sms.manage;

import java.rmi.RemoteException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import com.trainshop.sms.client.SingletonClient;

import net.sf.json.JSONObject;

/**
 * 亿美短信通道
 */
public class YiMeiSend implements SmsChannelInterface{
	
	public int sendMessage(TextMessage message){
		ResourceBundle bundle=PropertyResourceBundle.getBundle("sms");
		JSONObject jsonObject = JSONObject.fromObject(message.getContent());
		String content = "";
		//选择短信模板
		if(message.getTemplate().equals("redgift")){
			content = bundle.getString("yimeiTemplateRedgift");
			content = content.replace("code", jsonObject.get("code").toString());
		}else if(message.getTemplate().equals("login")){
			//登录模板
			content = bundle.getString("yimeiTemplateLogin");
			content = content.replace("code", jsonObject.get("code").toString());
			content = content.replace("product", jsonObject.get("product").toString());
		}else if(message.getTemplate().equals("plan")){
			content = bundle.getString("yimeiTemplatePlan");
			content = content.replace("code", jsonObject.get("code").toString());
			content = content.replace("msg", jsonObject.get("msg").toString());
		}
		
		
		
		int n = -1;
		try {
			n = SingletonClient.getClient().sendSMS(new String[] { message.getPhone() }, content, "", 5);// 带扩展码
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return n;
	}

}
